#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define all(x)          (x).begin(),(x).end()
typedef long long       ll;

typedef vector<int>     VI;
typedef vector<string>  VS;
typedef vector<VI>      VVI;

typedef pair<int, int>  PII;
typedef vector<PII>     VPII;
#define X               first
#define Y               second
#define mp              make_pair

#define FORE(e,c)       for(__typeof((c).begin()) e=(c).begin();e!=(c).end();e++)
#define RFORE(e,c)      for(__typeof((c).rbegin()) e=(c).rbegin();e!=(c).rend();e++)

#define two(x) (1<<(x))
#define twoll(x) ((long long)1<<(x))
#define contain(s,x) (((s)&two(x))!=0)
#define containll(s,x) (((s)&twoll(x))!=0)

#define db(a)           cout << #a << "=" << a << " "
#define dbn             cout << endl
#define dbs(str)        cout << str
template<class T> void print(vector<T> v) { cout << "["; if (v.size()) cout << v[0]; for (unsigned i = 1; i < v.size(); i++) cout << ", " << v[i];cout << "]\n"; }
template<class T> void print(vector<vector<T> > v) { cout << "[ ---\n"; if (v.size()) cout << " ", print(v[0]); for (unsigned i = 1; i < v.size(); i++) cout << " ", print(v[i]); cout << "--- ]\n"; }
template<class T1, class T2> void print(pair<T1, T2> p) { cout << "{" << p.first << ", " << p.second << "}"; }
template<class T1, class T2> void print(vector<pair<T1, T2> > v) { cout << "["; if (v.size()) print(v[0]); for (unsigned i = 1; i < v.size(); i++) cout << ", ", print(v[i]);cout << "]\n"; }
template<class T> inline T sqr(T x) { return x*x; }

template<class T> inline int chkmin(T& a, T b) { if (a>b) {a=b; return 1;} return 0; }
template<class T> inline int chkmax(T& a, T b) { if (a<b) {a=b; return 1;} return 0; }

//string STR(long long n) { char tmp[20]; lltoa(n,tmp,10); return string(tmp); }
//long long LL(string s) { return atoll(s.c_str()); }
template <class Ty, class Tx> Ty to(const Tx &x) { Ty y; stringstream ss; ss<<x; ss>>y; return y; }

const int INF = 1000000007;
const double EPS = 1e-10;

char buf[1<<20];

int CUR_CASE;
int TOTAL_CASES;

string str;

void INITIALIZE()
{
	gets(buf);
	str = buf;
}

#define SUBMIT 1

int main() {
#if !SUBMIT
	freopen("DATA.in", "rt", stdin);
	freopen("DATA.ou", "wt", stdout);
	clock_t STARTTIME, ENDTIME;
	STARTTIME = clock();
#endif

	gets(buf);
	TOTAL_CASES = atoi(buf);
	
	for (CUR_CASE = 1; CUR_CASE <= TOTAL_CASES; ++CUR_CASE)
	{
		INITIALIZE();
		
		int l = 0, r = str.length();
		while (r-l > 1)
		{
			int m = (l+r)/2;
			bool f = 0;
			for (int i = 0; i < str.length()-m+1; ++i)
				if (str.find(str.substr(i,m),i+1) != -1)
				{
					f = 1;
					break;
				}
			if (f)
				l = m;
			else
				r = m;
		}
		printf("%d\n",l);
	}

#if !SUBMIT
	ENDTIME = clock();
	cerr << "elapsed time : " << ENDTIME-STARTTIME << "ms";
#endif
	return 0;
}





